<?php
class IndexAction extends Action {
	public function index() {
		$code=I('code');
		$result=get_access_token_for_code($code);
		$access_token=$result['access_token'];
        //dump($$result);die;
		$openid=$result['openid'];
		$userinfo=get_msg_by_openid($access_token,$openid);
		wx_sub_scribe($openid,$userinfo);
		
		
		
		$ListNew = M('Products') -> where(array('ProStau' => 1)) -> select();
		$ListHot = M('Products') -> where(array('ProStau' => 2)) -> select();
		$ListSal = M('Products') -> where(array('ProStau' => 3)) -> select();
		$ListAd = M('Products') -> where(array('ProAd' => 1)) -> select();
		$this -> assign('ListNew', $ListNew);
		$this -> assign('ListHot', $ListHot);
		$this -> assign('ListSal', $ListSal);
		$this -> assign('ListAd', $ListAd);
		$this -> display();
	}

	public function ProductList() {
		$AllPro = M('Products') -> where(array('ShopID' => 1)) -> select();
		//dump(count($AllPro));
		$this -> assign('AllPro', $AllPro) -> display();
	}

	public function ProDetail() {
		$ProID = I('ProID');
        //p($ProID);
        
        $isValuation=M('pro_valuation')->where("ProId='$ProID'")->select();
        $ProDetails=M('pro_details')->where("ProId='$ProID'")->select();
		$Detail = M('Products') -> where("ProID = '$ProID'") -> select();
       
        //p($ProDetails);
		
        $this->assign('Detail',$Detail)
            ->assign('proDetails',$ProDetails)
            ->assign('valuationItem',$isValuation)
            ->display();

	}
    
    
    
    //查找商品
    public function seachPro(){
        $sName=$_POST['sName'];
        $ProIds=seachPro($sName);
        //p($sName);
        $data=array();//存放结果的数组
        foreach ($ProIds as $key => $value) {
            array_push($data,getProducts($value)[0]);
        }
        //p($data);
        $this->ajaxReturn($data);
        
    }
    
    //累计评论
    public function getVCount(){
        //获取参数
        $pId=$_POST['isProId'];
        $temp=M('pro_valuation')->where("ProId='$pId'")->select();
        
        if(count($temp)<=0)
            return 0; 
        $this->ajaxReturn(count($temp));    
        
    }

}
